package org.htmlparser.visitors;

import java.util.Locale;
import org.htmlparser.Text;

public class StringFindingVisitor extends NodeVisitor
{
  private int foundCount;
  private Locale locale;
  private boolean multipleSearchesWithinStrings;
  private String stringToFind;

  public StringFindingVisitor(String paramString)
  {
    this(paramString, null);
  }

  public StringFindingVisitor(String paramString, Locale paramLocale)
  {
    if (paramLocale == null)
      localLocale = Locale.ENGLISH;
    while (true)
    {
      this.locale = localLocale;
      this.stringToFind = paramString.toUpperCase(this.locale);
      this.foundCount = 0;
      this.multipleSearchesWithinStrings = false;
      return;
      localLocale = paramLocale;
    }
  }

  public void doMultipleSearchesWithinStrings()
  {
    this.multipleSearchesWithinStrings = true;
  }

  public int stringFoundCount()
  {
    return this.foundCount;
  }

  public boolean stringWasFound()
  {
    int i;
    if (stringFoundCount() != 0)
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public void visitStringNode(Text paramText)
  {
    String str = paramText.getText().toUpperCase(this.locale);
    if ((!(this.multipleSearchesWithinStrings)) && (str.indexOf(this.stringToFind) != -1))
      this.foundCount = (1 + this.foundCount);
    while (true)
    {
      do
        return;
      while (!(this.multipleSearchesWithinStrings));
      int i = -1;
      do
      {
        i = str.indexOf(this.stringToFind, i + 1);
        if (i != -1)
          this.foundCount = (1 + this.foundCount);
      }
      while (i != -1);
    }
  }
}